<template>
  <div class="maina">
    <arrow :topList="topList"></arrow>
    <div>
      <div class="content">
        <article class="content_box">
          <div class="title_left">产品运营 > 申请审核</div>

          <!-- <div @click="goEdit()">点我详情list，编辑或者添加</div> -->

          <div class="app-container">
            <div style="margin-left: -43px;"> <el-form :model="queryParams" ref="queryForm" size="small" :inline="true"
                v-show="showSearch" label-width="100px">
                <el-form-item label="关键词：" prop="keyword">
                  <el-input v-model="queryParams.keyword" placeholder="请输入关键词" clearable
                    @keyup.enter.native="handleQuery" />
                </el-form-item>

                <el-form-item label="渠道类型：" prop="type">
                  <el-select v-model="queryParams.type" placeholder="请选择类型">
                    <el-option v-for="item in status" :key="item.value" :label="item.label" :value="item.value">
                    </el-option>
                  </el-select>
                </el-form-item>


                <el-form-item>
                  <el-button type="primary" icon="el-icon-search" style="background-color: #165DFF;border-color: #165DFF;"
                    @click="handleQuery">搜索</el-button>
                  <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
                </el-form-item>
              </el-form></div>
            <el-row :gutter="10" class="mb8">
              <el-col :span="1.5" style="margin-left: -20px;">
                <el-button type="primary" size="mini" icon="el-icon-plus" @click="handleAdd">新增</el-button>
              </el-col>
              <el-col :span="1.5">
                <el-button type="danger" size="mini" plain icon="el-icon-delete" :disabled="multiple"
                  @click="handleDelete">删除</el-button>
              </el-col>
              <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row>
            <!-- 
            <el-row :gutter="10" class="mb8">

              <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
            </el-row> -->

            <el-table stripe v-loading="loading" :data="topicList" size="medium" @selection-change="handleSelectionChange">
              <el-table-column type="selection" width="55" align="center" />
              <el-table-column label="渠道编号" width="100" prop="platformXh" />
              <el-table-column label="渠道名称" align="center" prop="name" />
              <el-table-column label="渠道类型" width="80" align="center" prop="type">
                <template slot-scope="scope">
                  <el-tag v-if="scope.row.type == 1" type="warning">自有</el-tag>
                  <!-- <el-tag v-if="scope.row.type == 1" type="warning">停用(永久停用)</el-tag> -->
                  <el-tag v-if="scope.row.type == 3" type="warning">三方</el-tag>
                </template>
              </el-table-column>
              <el-table-column label="渠道更新时间" width="100" align="center" prop="updateTime" />
              <el-table-column label="渠道创建时间" width="100" align="center" prop="createTime" />
              <el-table-column label="授权账号" align="center" prop="updateTime" />

              <el-table-column label="授权状态" align="center" prop="status">
                <template slot-scope="scope">
                  <el-tag v-if="scope.row.status == 0" type="success">使用中</el-tag>
                  <el-tag v-if="scope.row.status == 1" type="danger">已关闭</el-tag>
                  <el-tag v-if="scope.row.status == 3" type="warning">短期停用</el-tag>
                </template>
              </el-table-column>
              <el-table-column label="渠道用途" align="center" prop="empowerUseto" />
              <el-table-column label="渠道状态" align="center" prop="state">

                <template slot-scope="scope">
                  <el-tag v-if="scope.row.state == 0" type="success">使用中</el-tag>
                  <el-tag v-if="scope.row.state == 1" type="danger">已关闭</el-tag>
                </template>
              </el-table-column>
              <el-table-column label="备注" align="center" prop="remark" />


              <el-table-column label="操作" fixed="right" align="center" width="200" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                  <el-button icon="el-icon-edit" size="small" type="success" plain @click="handleUpdate(scope.row)">编辑</el-button>

                </template>
              </el-table-column>
            </el-table>

            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
              :limit.sync="queryParams.pageSize" @pagination="getList" />
            <el-dialog :title="title" :visible.sync="open" width="680px" append-to-body>
              <el-form ref="form" :model="form" :rules="rules" label-width="100px">
                <el-row>
                  <el-col :span="24">
                    <el-form-item label="渠道名称" prop="name">
                      <el-input v-model="form.name" placeholder="请输入渠道名称" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="渠道类型" prop="type">
                      <el-radio-group v-model="form.type">
                        <el-radio label="1">自有</el-radio>
                        <el-radio label="3">三方</el-radio>
                      </el-radio-group>
                    </el-form-item>
                  </el-col>
                
                  <el-col :span="24">
                    <el-form-item label="渠道用途" prop="empowerUseto">
                      <el-input v-model="form.empowerUseto" placeholder="请输入渠道用途" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="渠道状态" prop="state">
                      <el-radio-group v-model="form.state">
                        <el-radio label="0">使用</el-radio>
                        <el-radio label="1">禁止</el-radio>
                      </el-radio-group>
                    </el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="备注" prop="remark">
                      <el-input v-model="form.remark" placeholder="请输入备注" />
                    </el-form-item>
                  </el-col>
                  <el-col :span="24">
                    <el-form-item label="授权平台" prop="shouqaun">
                      <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="weishou">微公号授权</el-button>
                      <el-button plain icon="el-icon-plus" size="mini" disabled>省平台授权</el-button>
                      <el-button plain icon="el-icon-plus" size="mini" disabled>终端大屏</el-button>

                    </el-form-item>
                  </el-col>

                </el-row>
              </el-form>
              <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="submitFormshou">确 定</el-button>
                <el-button @click="cancelshou">取 消</el-button>
              </div>
            </el-dialog>
          </div>


        </article>
      </div>
    </div>
  </div>
</template>

<script>
import arrow from '@/views/components/arrow'
import { listTopic, delMytopicChuGao } from '@/api/my/xuanti'
import { shenheList, chugaoList, yunzhang, yunzhangdetail, tijiaozhang, qudao, qudaodetail ,addqudao,delqudao,editqudao} from '@/api/my'

export default {
  components: { arrow },
  name: '',
  data() {
    return {
      reason: "",
      fengtime: "3",
      invation: {
        name: '',  //邀请人姓名
        phone: '',
        job: '',
        url: ''
      },
      tableData: [{
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1517 弄'
      }, {
        date: '2016-05-01',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1519 弄'
      }, {
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1516 弄'
      }],
      pop: {
        title: '',  //所选专家
        search: '', //搜索专家
      },
      activeName: 'first',
      options: [{
        value: '黄金糕',
        label: '黄金糕'
      }, {
        value: '双皮奶',
        label: '双皮奶'
      }, {
        value: '蚵仔煎',
        label: '蚵仔煎'
      }, {
        value: '龙须面',
        label: '龙须面'
      }, {
        value: '北京烤鸭',
        label: '北京烤鸭'
      }],
      value: '',
      openTiShen: false,
      tongvalue: "0",
      openn: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 文章选题表格数据
      topicList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        keyWords: null,
        // examineType: "2",
        // examineState: "2"
        // articleExamineState: null,
        // topicXh: null,
        // target: null,
        // digest: null,
        // outline: null,
        // results: null,
        // type: null,
        // schedule: null,
        // userId: null,
        // userName: null,
        // isDelete: null,
        // sourceMaterialId: null,
        // startTime: null,
        // endTime: null
      },
      processList: [
        { value: 1, label: '素材归集中' },
        { value: 2, label: '内容创作中' },
        { value: 3, label: '创作已完成' },
        { value: 4, label: '已提交审核' },
        { value: 5, label: '已收入成品库' },
        { value: 6, label: '产品分发中' },
      ],
      contentType: [
        { value: 1, label: '图片' },
        { value: 2, label: '视频' },
        { value: 3, label: '音频' },
        { value: 4, label: '动漫' },
        { value: 5, label: '挂图' },
      ],
      status: [
      { value: 1, label: '自有' },
        { value: 3, label: '三方' },
      ],
      qutype: [
        { value: 1, label: '自有' },
        { value: 3, label: '三方' },
      ],
      // 表单参数
      form: {
        name: "",
        empowerUseto: "",
        platformId: "",
        platformXh:"",
        remark:"",
        state:"",
        type:"",
        updateTime:"",
        userId:"",
        shouping:"微公众号"

      },
      // 表单校验
      rules: {
        name: [
          { required: true, message: "渠道名称不能为空", trigger: "blur" }
        ],
        type: [
          { required: true, message: "渠道类型不能为空", trigger: "blur" }
        ],
        state: [
          { required: true, message: "渠道状态不能为空", trigger: "blur" }
        ],
        shouping: [
          { required: true, message: "授权平台不能为空", trigger: "blur" }
        ],
      },
      topList: {
        title: '流程指引',
        list: [
          { name: '素材管理', img: 'blue' },
          { name: '内容创作', img: 'blue' },
          { name: '专家审核', img: 'blue' },
          { name: '产品分发', img: 'gray' },
          { name: '传播管理', img: 'gray' },
        ]
      },
      http: ""
    }
  },
  created() {
    this.getList();
    this.http = process.env.VUE_APP_ImgUrlHeader
    //  console.log(process.env.VUE_APP_ImgUrlHeader,"111")
    // this.form.platformId=this.$route.query.platformId
    // if(this.form.platformId){
    // }

  },
  methods: {
    handleClick(tab, event) {
      //  console.log(tab, event);
    },
    handleExam(row) {
      //提审
      this.tongvalue == "0"
      yunzhangdetail(row.userDataId).then(response => {
        this.form = response.data;
        this.form.examineStatus = "0"
        this.$forceUpdate()
        this.openn = true

      });
      console.log(123);
    },
    goEdit() {
      this.$router.push({ path: 'xuanti_edit' })
    },
    /** 查询文章选题列表 */
    getList() {
      this.loading = false;
      qudao(this.queryParams).then(response => {
        // response.rows.map(v => {
        //   let typeFind = this.contentType.find(values => values.value == v.type)
        //   if (typeFind !== undefined) {  //内容类型
        //     v.type = typeFind.label
        //   }
        //   let statusFind = this.status.find(r => r.value == v.articleExamineState)
        //   if (statusFind !== undefined) {  //审核状态
        //     v.articleExamineState = statusFind.label
        //   }
        //   let protosFind = this.protos.find(params => params.value == v.copyrightType)
        //   if (protosFind !== undefined) {
        //     v.copyrightType = protosFind.label
        //   }
        //   return v
        //   // console.log(v);

        // })
        this.topicList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.openn = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        name: "",
        empowerUseto: "",
        platformId: "",
        platformXh:"",
        remark:"",
        state:"",
        type:"",
        updateTime:"",
        userId:""

      };
      this.resetForm("form");
    },
    weishou() {

    },
    cancelshou() {
      this.open = false
      this.reset()
    },
    submitFormshou() {
      console.log(this.form,"111")
this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.platformId =="") {
            addqudao(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
              this.reset()

            });
          } else {
            editqudao(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;

              this.getList();
              this.reset()

            });
          }
        }
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.platformId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "新增渠道";
      // this.$router.push({ path: '/content/xuanti_edit', 'query': { 'type': 1 } })
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const topicId = row.platformId
      qudaodetail(topicId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改渠道";
      });
      console.log(row);
      // this.$router.push({ path: '/content/edit_content', query: { 'type': 2, 'articleId': row.articleId, 'topicId': row.topicId } })
    },
    /** 提交按钮 */
    submitForm() {
      let msg = ""
      if (this.tongvalue == "2" || this.tongvalue == "3") {
        if (this.reason) {

        } else {
          msg = "请输入原因"
          this.$modal.msgWarning(msg);
        }
      }
      if (this.tongvalue == "0") {
        msg = "请选择操作项"
        this.$modal.msgWarning(msg);
      }

      if (msg == "") {
        tijiaozhang({
          bannedTime: "",
          examineFailReason: this.reason,
          examineStatus: this.tongvalue,
          userDataId: this.form.userDataId,
          bannedTime: this.fengtime
        }).then(res => {
          this.$modal.msgSuccess("成功");
          this.openn = false;
          this.getList();
        })
      }

      // this.$refs["form"].validate(valid => {
      //   if (valid) {
      //     if (this.form.topicId != null) {
      //       updateTopic(this.form).then(response => {
      //         this.$modal.msgSuccess("修改成功");
      //         this.open = false;
      //         this.getList();
      //       });
      //     } else {
      //       addTopic(this.form).then(response => {
      //         this.$modal.msgSuccess("新增成功");
      //         this.open = false;
      //         this.getList();
      //       });
      //     }
      //   }
      // });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const articleId = row.platformId  || this.ids;
      this.$modal.confirm('是否确认删除渠道？').then(function () {
        return delqudao(articleId)
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => { });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/topic/export', {
        ...this.queryParams
      }, `topic_${new Date().getTime()}.xlsx`)
    }
  },

}
</script>
<style>
.has-gutter {
  /* background-color: red !important; */
}
</style>
<style lang='scss' scoped>
.titlefen {
  font-size: 18px;
  line-height: 50px;
  font-weight: bold;
}

.jibenxin {
  width: 95%;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  padding-bottom: 20px;

  .yongxinitem {
    width: 48%;
    font-size: 16px;
    font-family: Microsoft YaHei, Microsoft YaHei;
    font-weight: 400;
    color: #666666;
    line-height: 40px;
  }
}

.maina {
  background-color: #f5f5f5;

  .content {
    margin-top: 10px;
    background-color: white !important;

    .content_box {
      padding-left: 32px;

      .title_left {
        // margin-left: 23px;
        padding-top: 31px;
        font-size: 16px;
        font-family: Microsoft YaHei, Microsoft YaHei;
        font-weight: 700;
        color: #3D3D3D;
        line-height: 21px;
      }
    }
  }
}
</style>